package com.lepu.datajackson.config;

import java.util.function.Function;

public enum SensitiveStrategy {

    /**
     * Username sensitive strategy.
     */
    USERNAME(s -> s.replaceAll("(\\S)\\S(\\S*)", "$1*$2")),
    /**
     * Id card sensitive type.
     */
//    ID_CARD(s -> s.replaceAll("(\\d{4})\\d*(\\w{3})", "$1****$2")),
    ID_CARD(s -> s.replaceAll("(?<=\\w{4})\\w(?=\\w{3})", "*")),
    /**
     * Phone sensitive type.
     */
    PHONE(s -> s.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2")),
    /**
     * Address sensitive type.
     */
    ADDRESS(s -> s.replaceAll("(\\S{3})\\S{2}(\\S*)\\S{2}", "$1****$2****")),
    /**
     * email sensitive type.
     */
    EMAIL(s -> s.replaceAll("(\\S{2})\\S*(\\S{3})(@\\S)", "$1***$2$3"));

    private final Function<String, String> desensitizer;

    SensitiveStrategy(Function<String, String> desensitizer) {
        this.desensitizer = desensitizer;
    }

    public Function<String, String> desensitizer() {
        return desensitizer;
    }
}
